package com.khiker.tree.binary_tree;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class P257_BinaryTreePaths {
	private static final String SPLIT = "->";

	public List<String> binaryTreePaths(TreeNode root) {
		if (root == null) {
			return Collections.emptyList();
		}
		List<String> list = new ArrayList<>(64);
		calPath(root, "", list);
		return list;
	}


	private void calPath(TreeNode node, String sb, List<String> list) {
		if (node == null) {
			return;
		}
		sb += node.val;
		if (node.left == null && node.right == null) {
			list.add(sb);
		} else {
			calPath(node.left, sb + SPLIT, list);
			calPath(node.right, sb + SPLIT, list);
		}
	}


}
